package com.edu.solr_news.service.impl;

import com.edu.solr_news.bean.User;
import com.edu.solr_news.dao.UserDao;
import com.edu.solr_news.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpSession;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;

    @Override
    public String login(String account, String password, HttpSession session) {

        User user = userDao.findByAccount(account);
        if(user!=null ){
           if(password.equals(user.getPassword())){
               session.setAttribute("user", user);
               return "{\n" +
                       "  \"code\": 0,\n" +
                       "  \"msg\": \"登录成功\",\n" +
                       "  \"data\": {\n" +
                       "  }\n" +
                       "}";
           }else{
               return "{\n" +
                       "  \"code\": 1,\n" +
                       "  \"msg\": \"密码错误\",\n" +
                       "  \"data\": {\n" +
                       "  }\n" +
                       "}";
           }

        }else {
            return "{\n" +
                    "  \"code\": 1,\n" +
                    "  \"msg\": \"账户不存在\",\n" +
                    "  \"data\": {\n" +
                    "  }\n" +
                    "}";
        }
    }
}
